package com.tyf.jms;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.google.gson.Gson;
import com.tyf.model.ActionBody;
import com.tyf.model.ActionHeader;
import com.tyf.model.ActionMessage;
import com.tyf.model.Tollbooth_InVo;
import com.tyf.model.Tollbooth_OutVo;
import com.tyf.tool.DateUtil;

/**MQ 消息发送
 * @author 周广文:15146639681
 *
 * 2016年5月12日
 */
public class SenderApp {
	private static MessageSender sender = getMessageSender("springJMSConfiguration.xml");

	public static void send(String msg) {
		sender.send(msg);
	}

	public static MessageSender getMessageSender(String configLocation) {
		ApplicationContext context = new ClassPathXmlApplicationContext(configLocation);
		return (MessageSender) context.getBean("messageSender");

	}

	public static void main(String args[]) {
//		SenderApp.send("aaaaa");
//		sendA2EToMq("126.657102","45.768305","37ba193bbc27925b",""+new Date(),"A","50");
		
		System.out.println("服务器已启动");
//		sender.send("{\"head\":{\"time\":\"2016-10-17 15:11:46\",\"bizType\":\"OutGS\",\"clientName\":\"OBDSERVER\"},\"body\":{\"data\":{\"client_tiem\":\"2016-10-17 15:11:46\",\"username\":\"周广文\",\"plate_num\":\"黑A12345\",\"car_type\":\"1\",\"in_name\":\"入口站名称\",\"in_id\":\"123\",\"in_time\":\"2016-10-17 15:11:46\",\"order_time\":\"1:23:55\",\"mileage\":\"80\",\"tollbooths\":[{\"tollbooth_name\":\"A站\",\"tollbooth_num\":\"2\",\"deatil_out_time\":\"A站\"},{\"tollbooth_name\":\"B站\",\"tollbooth_num\":\"3\",\"deatil_out_time\":\"B站\"},{\"tollbooth_name\":\"C站\",\"tollbooth_num\":\"4\",\"deatil_out_time\":\"C站\"},{\"tollbooth_name\":\"D站\",\"tollbooth_num\":\"5\",\"deatil_out_time\":\"D站\"},{\"tollbooth_name\":\"V站\",\"tollbooth_num\":\"7\",\"deatil_out_time\":\"V站\"}],\"order_number\":\"1477968447\",\"gpslist\":[],\"obd_id\":\"ttttt\",\"tollbooth_num\":\"0008\"}}}","receivelistlog");
	}
	




	
   /*---------------------高速公路测试区---------------------------------*/
	/** 车辆入高速返回
	 * @param vo
	 */
	public static void sendTollbooth_InToMq(Tollbooth_InVo vo) {
		// TODO Auto-generated method stub
		 Gson gson = new Gson();
			ActionMessage msg = new ActionMessage();
			ActionHeader head = new ActionHeader();
			ActionBody body = new ActionBody();
			Map map = new HashMap();
			head.setTime(DateUtil.getNow());
			head.setClientName("OBDSERVER");
			head.setBizType("Tollbooth_In");
			body.setData(vo);
			msg.setHead(head);
			msg.setBody(body);
			System.out.println(gson.toJson(msg));
			sender.send(gson.toJson(msg));
	}
	
	
	/**车辆出高速公路返回
	 * @param vo
	 */
	public static void sendTollbooth_OutToMq(Tollbooth_OutVo vo) {
		// TODO Auto-generated method stub
		 Gson gson = new Gson();
			ActionMessage msg = new ActionMessage();
			ActionHeader head = new ActionHeader();
			ActionBody body = new ActionBody();
			Map map = new HashMap();
			head.setTime(DateUtil.getNow());
			head.setClientName("OBDSERVER");
			head.setBizType("Tollbooth_Out");
			body.setData(vo);
			msg.setHead(head);
			msg.setBody(body);
			System.out.println(gson.toJson(msg));
			sender.send(gson.toJson(msg));
	}
}
